package org.mybatis.example;

import java.lang.reflect.Array;
import java.util.*;

/**
 * 测试性能
 * 单线程  < 300ms
 * sync并发
 * 自旋锁
 * contMap
 *
 * @author Caleb
 * @date 2021/3/19 15:08
 * @description
 */
public class MyBatisEnhance {
  private final static Integer size = 10000000;

  private static Map<Class<?>, Object> mapperRegister = new HashMap(size);

  public static List<Class<?>> scannerMapper(String location) {
    List<Class<?>> list = new ArrayList<>();

    for (int i = 0; i < size; i++) {
      list.add(MyBatisEnhance.class);
    }
    return list;
  }

  public static synchronized void put(Class<?> clazz, Object obj){
      mapperRegister.put(clazz,obj);
  }

  public static void main(String[] args) {
    String location = "xxx.xml";
    List<Class<?>> classes = scannerMapper(location);

    long start = System.currentTimeMillis();
    classes.parallelStream().forEach(clazz -> put(clazz,new Object()));
    long end = System.currentTimeMillis();
    System.out.println(end - start);
  }
}
